package com.kanesoft.android.gdx.background;

import com.badlogic.gdx.Gdx;
import com.kanesoft.android.gdx.widgets.sprites.SpriteInfo;
import com.kanesoft.android.gdx.widgets.sprites.SpriteWidget;
import com.kanesoft.android.gdx.widgets.sprites.SpriteSlideInfo;

public class BackgroundStickManControl {

    
    private SpriteWidget walkingMan;
    
    private int x;
    private int y;
    private int speedx;
    private int speedy; 
    
    public BackgroundStickManControl(int x0, int y0, int speedx, int speedy)  {
        
        x = x0;
        y = y0;
        this.speedx = speedx;
        this.speedy = speedy;
        
        SpriteInfo spInfo = new SpriteInfo("data/walking_stikman.png", 0.070f);
        spInfo.addSpriteSlide(new SpriteSlideInfo(0, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48*2, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48*3, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48*4, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48*5, 0, 48, 48));
        spInfo.addSpriteSlide(new SpriteSlideInfo(48*6, 0, 48, 48));
        
        walkingMan = new SpriteWidget(x, y, 100, 100, spInfo, null);
        walkingMan.flipSpriteHorizontal();
 
    }
    
    public void updatePosition(float deltaTime) {
        x+=speedx;
        y+=speedy;
        
        if (x < 0) { speedx = -speedx; walkingMan.flipSpriteHorizontal();}
        if (y < 0) speedy = -speedy;
        if (x > Gdx.graphics.getWidth()) {speedx = -speedx; walkingMan.flipSpriteHorizontal();}
        if (y > Gdx.graphics.getHeight()) speedy = -speedy;
        
        walkingMan.setSpritePosition(x, y);
    }
    
    
    
    
    
}
